<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\video\logic;
use think\facade\Hook;
use think\DB;
use util\Tree;
use think\facade\Debug;
use think\facade\Cache;
class VideoGoodslogic{

	/**
     * 获取视频信息
     * @param  int $user_id  用户id
     * @param  int $play_id  视频id
     * @author jason wang <120907037@qq.com>
     * @return mixed
     */
    public function getGoodsListByPlayid($play_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
                'play_id' => $play_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $rel_list = [];
            /********业务逻辑********/
            $map = [];
            $map['play_id'] = $play_id;
            $list = model('VideoPlayGoods') -> where($map) ->cache(true) -> select();
            foreach ($list as $key => $value) {
                $rel = controller('erp/Goodslogic', 'logic') -> getGoodsInfo($value['goods_id']);//dump($rel);
                if($rel['code'] == 200) $rel_list[] = $rel['data'];
            }
            //dump($play_id);dump($list);
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', (object)$rel_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
}